package com.project.demo.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.project.demo.entity.Admin;
import com.project.demo.entity.Affairs;
import com.project.demo.mapper.AdminMapper;
import com.project.demo.mapper.AffairsMapper;
import com.project.demo.vo.AffairsVo;
import com.project.demo.vo.MessageInfo;
import org.apache.catalina.Wrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Controller
public class LoginController {
    @Autowired(required = false)
    AdminMapper adminMapper;

    @RequestMapping("/dologin")
    @ResponseBody
    public MessageInfo dologin(Admin admin) {
        List<Admin> admins = adminMapper.selectList(Wrappers.query(admin));
        MessageInfo messageInfo = new MessageInfo();
        if (admins.isEmpty()) {
            messageInfo.setCode("no");
            return messageInfo;
        }
        messageInfo.setCode("yes");
        return messageInfo;
    }


    @RequestMapping("/addadmin")
    @ResponseBody
    public MessageInfo addadmin(Admin admin) {
        List<Admin> admins = adminMapper.selectList(Wrappers.query(admin));
        adminMapper.insertAdmin(admin);
        MessageInfo messageInfo = new MessageInfo();
        if (admins.isEmpty()) {
            messageInfo.setCode("1");
            return messageInfo;
        }
        messageInfo.setCode("0");


        return messageInfo;

    }

}